package cn.tedu.system.admin.controller;

import cn.tedu.system.admin.pojo.dto.AdminAddUserParam;
import cn.tedu.system.admin.pojo.dto.UpdateUserStatusDTO;
import cn.tedu.system.admin.pojo.dto.UserAddDto;
import cn.tedu.system.admin.pojo.dto.UserSaveParam;
import cn.tedu.system.admin.pojo.vo.AllUserVO;
import cn.tedu.system.base.response.JsonResult;
import cn.tedu.system.merchant.pojo.dto.MerchantCheckDto;
import cn.tedu.system.admin.service.AdminService;
import cn.tedu.system.merchant.pojo.vo.MerchantStatusVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import java.util.List;

@Slf4j
@Api(tags = "03.管理员模块")
@RestController
@RequestMapping("/api/v1/admin/")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @ApiOperation("添加用户")
    @ApiOperationSupport(order = 5)
    @PostMapping("addUser")
    public JsonResult addUser(@RequestBody AdminAddUserParam userAdd, @ApiIgnore HttpSession session) {
        log.debug("添加用户参数:{}", userAdd);
        adminService.addUser(userAdd, session);
        return JsonResult.ok();
    }

    @ApiOperation("查看所有用户")
    @ApiOperationSupport(order = 10)
    @GetMapping("selAllUser")
    public JsonResult selAllUser(@ApiIgnore HttpSession session) {
        log.debug("管理员查看所有用户");
        List<AllUserVO> userList = adminService.selAllUser();
        return JsonResult.ok(userList);
    }

    @ApiOperation("修改用户信息")
    @ApiOperationSupport(order = 20)
    @PostMapping("revise")
    public JsonResult status(@RequestBody UserSaveParam userSaveParam, @ApiIgnore HttpSession session) {
        log.debug("保存用户信息参数:{}", userSaveParam);
        adminService.makeStatus(userSaveParam,session);
        return JsonResult.ok();
    }

    @ApiOperation("删除用户功能")
    @ApiOperationSupport(order = 15)
    @PostMapping("delUser")
    public JsonResult delUser(Long userId, @ApiIgnore HttpSession session) {
        log.debug("删除用户参数:{}", userId);
        adminService.delUser(userId, session);
        return JsonResult.ok();
    }

    @ApiOperation("查看所有店铺功能")
    @ApiOperationSupport(order = 25)
    @GetMapping("selStore")
    public JsonResult selStore(@ApiIgnore HttpSession session) {
        log.debug("查看所有店铺");
        List<MerchantStatusVO> list = adminService.selAllStore(session);
        return JsonResult.ok(list);
    }

    @ApiOperation("查看需审核店铺功能")
    @ApiOperationSupport(order = 30)
    @GetMapping("selCheckStore")
    public JsonResult selCheckStore(@ApiIgnore HttpSession session) {
        log.debug("查看需要审核的店铺");
        List<MerchantStatusVO> list = adminService.selCheckStore(session);
        return JsonResult.ok(list);
    }

    @ApiOperation("审核店铺功能")
    @ApiOperationSupport(order = 40)
    @PostMapping("checkStore")
    public JsonResult checkStore(@RequestBody MerchantCheckDto merchantCheckDto, @ApiIgnore HttpSession session) {
        log.debug("审核店铺参数:{}", merchantCheckDto);
        adminService.checkStore(merchantCheckDto,session);
        return JsonResult.ok();
    }


    //更新用户状态--农睿昌
    @ApiOperation("修改用户状态")
    @ApiOperationSupport(order = 20)
    @PostMapping("reviseStatus")
    public JsonResult revise(@RequestBody UpdateUserStatusDTO updateUserStatusDTO, @ApiIgnore HttpSession session) {
        log.debug("修改用户状态参数:{}", updateUserStatusDTO);
        adminService.reviseUserStatus(updateUserStatusDTO);
        return JsonResult.ok();
    }
}
